home *** CD-ROM | disk | FTP | other *** search
- /*
- File: Collections.h
-
- Contains: Sample collection functions & classes
-
- Written by: Steve Smith
-
- Copyright: © 1995 by Apple Computer, Inc., all rights reserved.
-
- Description:
- CList: Generic unordered list
- COrderedList: Generic ordered list
- CFrameList: Unordered list of frames -
- frames automatically refcounted when
- added/removed from list.
- CQueue: Generic queue collection
- CStack: Generic stack collection
- */
-
-
- #ifndef _SAMPLECOLLECTIONS_
- #define _SAMPLECOLLECTIONS_
-
- // --- OpenDoc Includes ---
-
- #ifndef _ODTYPES_
- #include <ODTypes.h>
- #endif
-
- #ifndef SOM_ODFrame_xh
- #include <Frame.xh>
- #endif
-
- // --- OpenDoc Utilities ---
-
- #ifndef _ODNEW_
- #include <ODNew.h>
- #endif
-
- #ifndef _LINKLIST_
- #include "LinkList.h"
- #endif
-
- //------------------------------------------------------------------------------
- // Classes Defined by this Interface
- //------------------------------------------------------------------------------
-
- class CList;
- class CListIterator;
- class COrderedList;
- class COrdListIterator;
- class CFrameList;
- class CFrameListIterator;
- class CQueue;
- class CStack;
-
- //------------------------------------------------------------------------------
- // Forwards
- //------------------------------------------------------------------------------
-
- enum {
- kItemNotFound = -1,
- kListIsEmpty = 0
- };
-
- //------------------------------------------------------------------------------
- // Collection Class Definitions
- //------------------------------------------------------------------------------
-
- class CGenericLink: public Link {
- public:
- CGenericLink();
- CGenericLink(void* value);
- virtual ~CGenericLink();
-
- void* GetValue();
- void SetValue(void* value);
-
- protected:
- void* fValue;
- };
-
- class CFrameLink : public CGenericLink {
-
- public:
- CFrameLink();
- CFrameLink(ODFrame* frame);
- virtual ~CFrameLink();
-
- ODFrame* GetFrame();
- void SetFrame(ODFrame* frame);
- };
-
-
- class CList {
- public:
- CList();
- virtual ~CList();
-
- ODBoolean IsEmpty() const;
- ODULong Count() const;
- ODBoolean Contains(const void* value);
- void DeleteAllLinks();
- void RemoveAllLinks();
- void Delete(void* value);
- void Remove(void* value);
- void Add(void* value);
-
- private:
- LinkedList fList;
-
- friend class CListIterator;
- };
-
- class CListIterator {
- public:
- CListIterator() {}
- CListIterator(CList* list);
- virtual ~CListIterator();
-
- void* First();
- void* Next();
- void* Previous();
- void* Last();
- void* Current();
- ODBoolean IsNotComplete();
- void RemoveCurrent();
- void DeleteCurrent();
-
- protected:
- LinkedListIterator* fIter;
- };
-
-
- class COrderedList {
- public:
- COrderedList();
- COrderedList(COrderedList *list);
- virtual ~COrderedList();
-
- ODBoolean IsEmpty() const;
- ODULong Count() const;
- ODBoolean Contains(const void* value);
- ODUShort Position(const void* value);
- void DeleteAllLinks();
- void RemoveAllLinks();
- void Delete(void* valeu);
- void Remove(void* value);
- void* RemoveFirst();
- void* RemoveLast();
- void AddBefore(const void* existing, void* value);
- void AddAfter(const void* existing, void* value);
- void AddFirst(void* value);
- void AddLast(void* value);
- void* After(const void* value) const;
- void* Before(const void* value) const;
- void* First() const;
- void* Last() const;
-
- private:
- LinkedList fList;
-
- friend class COrdListIterator;
- };
-
- class COrdListIterator : public CListIterator {
- public:
- COrdListIterator(COrderedList* list);
- virtual ~COrdListIterator();
- };
-
-
- class CFrameList {
- public:
- CFrameList();
- virtual ~CFrameList();
-
- ODBoolean IsEmpty() const;
- ODULong Count() const;
- ODBoolean Contains(const ODFrame* frame);
- void Remove(ODFrame* frame);
- void Add(ODFrame* frame);
- ODFrame* GetFrame();
-
- private:
- LinkedList fList;
-
- friend class CFrameListIterator;
- };
-
- class CFrameListIterator {
- public:
- CFrameListIterator(CFrameList* list);
- ~CFrameListIterator();
-
- ODFrame* First();
- ODFrame* Next();
- ODFrame* Previous();
- ODFrame* Last();
- ODFrame* Current();
- ODBoolean IsNotComplete();
- void ReleaseCurrent();
-
- private:
- LinkedListIterator* fIter;
- };
-
- class CStack {
- public:
- CStack();
- ~CStack();
-
- ODBoolean IsEmpty();
- void EmptyStack(ODBoolean deleteEntries = kODFalse);
- ODUShort SetSize(ODUShort maxDepth);
- ODBoolean PushEntry(void* entry);
- void* PopEntry();
-
- private:
- ODUShort fMaxDepth;
- LinkedList fStack;
- };
-
- class CQueue {
- public:
- CQueue();
- ~CQueue();
-
- ODBoolean IsEmpty();
- void EmptyQueue(ODBoolean deleteEntries = kODFalse);
- ODUShort SetSize(ODUShort maxEntries);
- ODBoolean AddEntry(void* entry);
- void* GetEntry();
-
- private:
- ODUShort fMaxEntries;
- LinkedList fQueue;
- };
-
- #endif //_SAMPLECOLLECTIONS_
-
-